
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Pe Bong
 */
public class Bank {
    ArrayList arr;
    int i = 0;
    int lastAccNo = 0;
    float amount = 0;
    int testAccNo;
    Account[] Acc;

    public Bank() {
        Acc = new Account[100];

        for (i = 0; i < Acc.length; i++) {
            Acc[i] = new Account();
        arr = new ArrayList();
        }
    }

    Scanner input = new Scanner(System.in);

    public void createAcc(Account acco) {
        System.out.println("*** Creating Account ***");
        System.out.println("Enter your First Name: ");
        acco.fName = input.next();
        System.out.println("Enter your Last Name :");
        acco.lName = input.next();
        acco.accNo = lastAccNo + 1;
        lastAccNo = acco.accNo;
        System.out.println("Enter your balance :");
        acco.bal = input.nextFloat();
        System.out.println("Your AccountNo is : " + acco.accNo);

        System.out.println("Enter your password:");
        acco.accPass = input.next();
        Acc[lastAccNo - 1] = acco;
        System.out.print(" Your creation is successful.Congratulation! ");
        Acc[lastAccNo - 1].toString();
        arr.add(lastAccNo);
    }

    public void display() {
        System.out.println("*** Accounts Details ***");
        System.out.format("   %1$-1s   |   %2$s   |   %3$8s   |   %4$-10s   |\n", "FirstName", "LastName", "AccountNo", "Balance");
        for (i = 0; i < lastAccNo; i++) {
            System.out.print(Acc[i].toString());
        }
    }

    public void deposit() {
        while (true) {
            System.out.print("Enter your AccountNo:");
            testAccNo = input.nextInt();
            System.out.print("Enter the amount you wan to deposit :");
            amount = input.nextFloat();
            ((Account)arr.get(i)).accNo = testAccNo;
            if (testAccNo > 0 && amount >= 100) {
                break;
            } else {
                System.out.print("the AccountNo not available or amount not correct (amount >=100)");
            }
        }
        boolean flag = true;
        for (i = 0; i < lastAccNo; i++) {
            if (testAccNo == Acc[i].accNo) {
                System.out.println("Your balance before deposit:" + Acc[i].bal);
                Acc[i].bal = Acc[i].bal + amount;
                System.out.println("Your balance after deposit:" + Acc[i].bal);
               
                flag = false;
            }
            }
            if (flag == true) {
                System.out.print("There is no Account");
            }
        }

    

    public void withdraw() {
        boolean flag = true;
        while ( flag == true) {
            System.out.print("Enter your AccountNo:");
            testAccNo = input.nextInt();
            System.out.println("Enter the amount you wan to withdraw :");
            amount = input.nextFloat();
            if (testAccNo > 0 && amount >= 100) {
               // break;
            } else {
                System.out.print("the AccountNo not available or amount not correct (amount >=100)");
            }
            for (i = 0; i < Acc.length; i++) {
                if (testAccNo == Acc[i].accNo) {
                    while (amount > Acc[i].bal) {
                        System.out.print("The amount your want to withdraw greater than your account balance ! Reenter your amount ,please !");
                        amount = input.nextFloat();
                    }
                    System.out.println("Your balance before withdraw : " + Acc[i].bal);
                    Acc[i].bal = Acc[i].bal - amount;
                    System.out.println("Your balance after withdraw : " + Acc[i].bal);
                }
                flag = false;
            }
            if (flag == true) {
                System.out.print("There is no account");
            }
        }

    }
}
